package com.aglhz.nature.fragment;

import java.util.List;


import com.aglhz.nature.R;
import com.aglhz.nature.ListView.MyGridView;
import com.aglhz.nature.adapter.ClassificationAdapter;
import com.aglhz.nature.modle.item.classification.ClassificationData;
import com.aglhz.nature.presenter.ClassificationPresenter;
import com.aglhz.nature.view.BrandIntroductionActivity;
import com.aglhz.nature.view.SecondClassScrollActivity;
import com.aglhz.nature.view.iv.ClassificationView;
import com.aglhz.scrollview.RollHeaderView;

import cz.msebera.android.httpclient.client.cache.Resource;


import butterknife.Bind;
import butterknife.ButterKnife;




import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

public class ClassificationFragment extends Fragment implements
		ClassificationView {
	private static String TAG = ClassificationFragment.class.getName();
	private ClassificationPresenter presenter;
	private ClassificationAdapter adapter;
	private List<ClassificationData> listData;
	private RollHeaderView class_rollHeaderView;
private ScrollView class_ScrollView;
private LinearLayout linearlayout;
//	@Bind(R.id.class_rollHeaderView)
//	RollHeaderView class_rollHeaderView;
	@Bind(R.id.gridview)
	MyGridView gridview;

	// private GridView gridview;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View view = inflater.inflate(R.layout.classificationfragment, null);
		ButterKnife.bind(this, view);
		class_rollHeaderView=(RollHeaderView) view.findViewById(R.id.class_rollHeaderView);
		class_ScrollView=(ScrollView) view.findViewById(R.id.class_ScrollView);
		linearlayout=(LinearLayout) view.findViewById(R.id.linearlayout);
		class_rollHeaderView.setOnHeaderViewClickListener(new RollHeaderView.HeaderViewClickListener() {
			@Override
			public void HeaderViewClick(int position) {
				
				Intent intent=new Intent(getActivity(),SecondClassScrollActivity.class);
				intent.putExtra("classification_scroll", presenter.getLink().get(position));
				startActivity(intent);
				
			}
		});
		// gridview=(MyGridView) view.findViewById(R.id.gridview) ;
		presenter = new ClassificationPresenter(this);
		// basePresenter register
		presenter.register();
		
		presenter.loadData();
		
		return view;
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		// basePresenter unregister
		presenter.unregister();
	}



	// 设置url数组，展示轮播图
		@Override
		public void showSrcollImage(List<String> urls) {

			class_rollHeaderView.setImgUrlData(urls);
		}
	
	@Override
	public void setList(final List<ClassificationData> data) {
		adapter = new ClassificationAdapter(data, getActivity());
		gridview.setAdapter(adapter);

	}

	@Override
	public void dismissScrollImage() {

		class_rollHeaderView.setVisibility(View.GONE);


		
		
	}
}
